import numpy as np
import operator
def classify(inx,dataset,labels,k):
	inx=np.mat(inx)
	dataset=np.mat(dataset)
	labels=np.mat(labels)
	datasize=dataset.shape[0]
	diffmat=np.tile(inx,(datasize,1))-dataset#扩充输入数据与训练数据容量相当，矩阵做减法，在算向量间的距离
	sqdiffmat=np.array(diffmat)**2
	sqdistance=sqdiffmat.sum(axis=1)#简单的欧氏距离（x-x）**2+（y-y）**2+（z-z）**2
	distances=sqdistance**0.5
	sortedDistIndicies = distances.argsort()
	classCount={}
	for i in range(k):  
		voteIlabel = labels[0,sortedDistIndicies[i]]  
		classCount[voteIlabel] = classCount.get(voteIlabel,0) + 1  
	sortedClassCount = sorted(classCount.items(), key=operator.itemgetter(1), reverse=True)
	print(type(sortedClassCount))
	return sortedClassCount[0][0] 
